<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
	<% String path=request.getContextPath(); String basePath=request.getScheme() + "://" + request.getServerName() + ":"
		+ request.getServerPort() + path + "/" ; %>

		<!DOCTYPE html>
		<html>

		<head>
			<base href="<%=basePath%>">
			<title>海科新源业务协同管理平台(CMP)</title>
			<script type="text/javascript" src="<%=path%>/resourse/js/jquery.min.js"></script>
			<script type="text/javascript" src="resourse/jquery-easyui-1.4.5/jquery.easyui.min.js"></script>
			<script type="text/javascript" src="resourse/js/common.js"></script>
			<link rel="alternate icon" type="image/png" href="<%=path%>/resourse/AmazeUI-2.7.2assets/i/favicon.png">
			<link rel="stylesheet" href="<%=path%>/resourse/AmazeUI-2.7.2/assets/css/amazeui.min.css" />
			<link rel="stylesheet" href="<%=path%>/resourse/AmazeUI-2.7.2/assets/css/admin.css">
			<link rel="stylesheet" type="text/css" href="resourse/jquery-easyui-1.4.5/themes/metro/easyui.css">
			<link rel="stylesheet" type="text/css" href="resourse/jquery-easyui-1.4.5/themes/icon.css">
			<link rel="stylesheet" type="text/css" href="resourse/jquery-easyui-1.4.5/themes/color.css">

			<style>
				body {
					background-color: #b4daed;
				}

				.header {
					text-align: center;
				}

				.header h1 {
					font-size: 200%;
					color: #333;
					margin-top: 30px;
				}

				.header p {
					font-size: 14px;
				}
			</style>
		</head>

		<body>
			<script>
				// 供应商注册对话框打开
				function registerSupply() {
					$('#supplyRegister-form').form('clear');
					$('#supplyRegister').window('open');
				}

				function resetPwdWindow() {
					$('#resetPwdWindow-form').form('clear');
					$('#pwdResetWidow').window('open');
				}

				function resetPwd() {
					// var code = $('#txtCode').val();
					var name = $('#txtLoginName').val();
					$.ajax({
						type: "get",
						url: "api/supply/sendMail",
						dataType: "json",
						data: {
							loginName: name
						},
						success: function (data) {
							if (data.code == 60200) {

							} else {
							}
							$.messager.alert('提示', data.msg);
						},
						error: function (XMLHttpRequest, textStatus,
							errorThrown) {
							alert(errorThrown);
						}
					});
				}

				function login() {
					var name = $('#loginname').val();
					var pwd = $('#xyofficepassword').val();
					$.ajax({
						type: "post",
						url: "api/supply/supplierLogin",
						dataType: "json",
						data: {
							loginName: name,
							pwd: pwd
						},
						success: function (data) {
							if (data.code == 60200) {
								localStorage.setItem("tokenSupply", data.data.tokenString);
								localStorage.setItem("supplyUser", JSON.stringify(data.data.supplyUserModel));
								window.location.href = "<%=basePath%>supply/SupplyOfdefault";
							} else {
								alert('用户名或密码不正确');
							}
						},
						error: function (XMLHttpRequest, textStatus,
							errorThrown) {
							alert(errorThrown);
						}
					});
				}
				//为button设置回车事件（百度搜索所得）
				//为keyListener方法注册按键事件
				document.onkeydown = keyListener;
				function keyListener(e) {
					// 当按下回车键，执行我们的代码
					if (e.keyCode == 13) {
						login();
					}
				}

			</script>
			<div class="header">
				<div class="am-g">
					<h1>海科新源业务协同管理平台(CMP)</h1>
					<!-- 			<p> -->
					<!-- 				Integrated Development Environment<br />代码编辑，代码生成，界面设计，调试，编译 -->
					<!-- 			</p> -->
				</div>
				<hr />
			</div>
			<div class="am-g">
				<div class="am-u-lg-6 am-u-md-8 am-u-sm-centered">
					<!-- 			<h3>登录</h3> -->
					<!-- 			<hr> -->
					<!-- 			<div class="am-btn-group"> -->
					<!-- 				<a href="#" class="am-btn am-btn-secondary am-btn-sm"><i -->
					<!-- 					class="am-icon-github am-icon-sm"></i> Github</a> <a href="#" -->
					<!-- 					class="am-btn am-btn-success am-btn-sm"><i -->
					<!-- 					class="am-icon-google-plus-square am-icon-sm"></i> Google+</a> <a -->
					<!-- 					href="#" class="am-btn am-btn-primary am-btn-sm"><i -->
					<!-- 					class="am-icon-stack-overflow am-icon-sm"></i> stackOverflow</a> -->
					<!-- 			</div> -->
					<br> <br>

					<form method="post" class="am-form">
						<label>登录名:</label> <input type="email" name="loginname" id="loginname" value=""> <br> <label
							for="password">密码:</label>
						<input type="password" name="xyofficepassword" id="xyofficepassword" value="">
						<!-- 				<br> <label for="remember-me"> <input id="remember-me" -->
						<!-- 					type="checkbox"> 记住密码 -->
						<!-- 				</label> <br /> -->
						<br />
						<div class="am-cf">
							<input type="button" style="color: #0a628f" onclick="registerSupply()" value="注册" />
							<input type="button" style="color: #0a628f" onclick="resetPwdWindow()" value="忘记密码" /> <a
								href="resourse/海科新源业务协同管理平台使用说明书-供应商.pdf">使用手册</a> <input type="button" value="登录"
								onclick="login()" class="am-btn am-btn-default am-btn-sm am-fr">
							<!-- 						 <input -->
							<!-- 						type="submit" name="" value="登 录" -->
							<!-- 						class="am-btn am-btn-primary am-btn-sm am-fl"> -->
							<!--         <input type="submit" name="" value="忘记密码 ^_^? " class="am-btn am-btn-default am-btn-sm am-fr"> -->
						</div>
					</form>
					<hr>
					<!-- 			<p>山东海科新源材料科技股份有限公司.</p> -->
				</div>

			</div>

			<div id="pwdResetWidow" class="easyui-window" closed="true" modal="true" maximized="false" title="重置密码"
				style="width: 550px; height: 300px; padding: 10px 20px">
				<form id="resetPwdWindow-form" class="ssec-form" style="margin: 0; padding: 20px 50px">
					<table class="table">
						<tr>
							<td>
								<div style="margin-bottom: 10px">注册账号：</div>
							</td>
							<td>
								<div style="margin-bottom: 10px">
									<input id="txtLoginName" class="easyui-validatebox textbox"
										data-options="required:true" />
								</div>
							</td>
						</tr>
						<!-- <tr>
							<td>
								<div style="margin-bottom: 10px">公司编码：</div>
							</td>
							<td>
								<div style="margin-bottom: 10px">
									<input id="txtLoginName" class="easyui-validatebox textbox"
										data-options="required:true" />
								</div>
							</td>
						</tr> -->
					</table>
					<div style="padding: 5px; text-align: right;">
						<input type="button" value="发送邮件" onclick="resetPwd()">
					</div>
				</form>
			</div>

			<div id="supplyRegister" class="easyui-window" closed="true" modal="true" maximized="false" title="供应商注册"
				style="width: 550px; height: 400px; padding: 10px 20px">
				<form id="supplyRegister-form" class="ssec-form" style="margin:0;padding:20px 50px">

					<table class="table">
						<tr>
							<td>
								<div style="margin-bottom:10px">公司名称：</div>
							</td>
							<td>
								<div style="margin-bottom:10px">
									<input id="registerSupplierName" class="easyui-validatebox textbox"
										data-options="required:true" />
									<span>注册后公司名称不可修改！！！</span>
								</div>
							</td>
						</tr>
						<tr>
							<td>
								<div style="margin-bottom:10px">姓名：</div>
							</td>
							<td>
								<div style="margin-bottom:10px">
									<input id="userName" class="easyui-validatebox textbox"
										data-options="required:true" />
								</div>
							</td>
						</tr>
						<tr>
							<td>
								<div style="margin-bottom:10px">注册账号：</div>
							</td>
							<td>
								<div style="margin-bottom:10px">
									<input id="registerLoginName" class="easyui-validatebox textbox"
										data-options="required:true" />
								</div>
							</td>
						</tr>
						<tr>
							<td>
								<div style="margin-bottom:10px">密码：</div>
							</td>
							<td>
								<div style="margin-bottom:10px">
									<input id="loginPassword" class="easyui-validatebox textbox"
										data-options="required:true" />
								</div>
							</td>
						</tr>
						<tr>
							<td>
								<div style="margin-bottom:10px">联系方式：</div>
							</td>
							<td>
								<div style="margin-bottom:10px">
									<input id="telePhoneNumber" class="easyui-numberbox" data-options="required:true" />
								</div>
							</td>
						</tr>
						<tr>
							<td>
								<div style="margin-bottom:10px">邮箱：</div>
							</td>
							<td>
								<div style="margin-bottom:10px">
												<input id="infMail" name="infMail" class="easyui-textbox"
													data-options="required:true,validType:'email'" />
								</div>
							</td>
						</tr>

					</table>
					<div style="padding: 5px; text-align: right;">
						<input type="button" value="保存" onclick="saveSupplyRegister()">
					</div>
				</form>
			</div>

		</body>
		<script type="text/javascript">
			// 供应商注册保存
			function saveSupplyRegister() {
				/* $('#supplyRegister-form').form('submit', {
					 url: 'supply/supplierRegister',
					 iframe: false,
					 onSubmit: function () {
						 return !$(this).form('validate');
					 },
					 success: function (result) {
						 var data = JSON.parse(result);
						 if (data.code != 60200) {
							 $.messager.alert({
								 title: 'Error',
								 msg: data.msg
							 });
						 } else {
							 $('#supplyRegister').window('close');        // close the dialog
						 }
					 }
				 });*/
				if (!$('#supplyRegister-form').form('validate')) {
					return;
				}
				var registerSupplierName = $('#registerSupplierName').val();
				var userName = $('#userName').val();
				var telePhoneNumber = $('#telePhoneNumber').val();
				var registerLoginName = $('#registerLoginName').val();
				var loginPassword = $('#loginPassword').val();
				// 校验
				var zg = /^[0-9a-zA-Z]*$/;
				if (!zg.test(registerLoginName)) {
					$.messager.alert('消息', '账号不得包含汉字及特殊字符');
					return;
				}
				if (!zg.test(loginPassword)) {
					$.messager.alert('消息', '密码不得包含汉字及特殊字符');
					return;
				}
				$.ajax({
					type: "post",
					url: "api/supply/supplierRegister",
					dataType: "json",
					// contentType: 'application/json',
					data: {
						registerSupplierName: registerSupplierName,
						userName: userName,
						registerLoginName: registerLoginName,
						loginPassword: loginPassword,
						telePhoneNumber: telePhoneNumber,
						 infMail: $('#infMail').textbox('getValue')
					},
					success: function (result) {
						console.log('result>>>>', result)
						console.log('result>>>>', result.code)
						// var data = JSON.parse(result);
						if (result.code != 60200) {
							$.messager.alert('消息', result.msg);
						} else {
							$.messager.alert('消息', result.msg);
							$('#supplyRegister').window('close');
						}
					},
					error: function (XMLHttpRequest, textStatus, errorThrown) {
						$.messager.alert('消息', errorThrown);
					}
				});
			}
		</script>


		</html>